<!DOCTYPE html>
<html>
<head>
    <meta charset='UTF-8'>
    <title>分析生命周期</title>
    <script src="../js/vue.js"></script>
</head>
<body>
    <div id="root" :x="n">
        <h2>当前的n值是{{n}}</h2>
        <button @click="add">点击n+1</button>
        <button @click="bye">销毁vm</button>
    </div>
</body>
<!--   JS   -->
    <script>
        new Vue({
            el:'#root',
           /*  template:`
                <div>
                    <h2>当前的n值是{{n}}</h2>
                    <button @click="add">点击n+1</button>
                </div>
            `, */
            data:{
                n:1
            },
            methods: {
                add(){
                    console.log('add')
                    this.n++
                },
                bye(){
                    console.log('bye')
                    this.$destroy()
                }
            },
            beforeCreate() {
                console.log('beforeCreate')
            },
            created() {
                console.log('created')
            },
            beforeMount() {
                console.log('beforeMount')
            },
            mounted() {
                console.log('mounted')
            },
            beforeUpdate() {
                console.log('beforeUpdate')
                //数据是新的，但页面是旧的，页面和数据不同步
            },
            updated() {
                console.log('updated')
            },
            beforeDestroy() {
                console.log('beforeDestroy')
                //this.add()
                //收尾操作
            },
            destroyed() {
                console.log('destroyed')
            },
        })
    </script>
</html>